<?php
class MGameRecord extends MY_Model {

	protected $table = 'core_game_record';
    
	public function getList($limit,$user_id, $sort=false){
		$this->db->select( $this->table.'.*');
		$this->db->distinct();
		$this->db->from($this->table);
		$this->db->where('user_id',$user_id);
		$this->db->limit($limit['limit'],$limit['offset']);
		$this->formfilter->doFilter();
		if($sort){
			$this->db->order_by('sort', 'asc');
		}else{
			$this->db->order_by('id', 'desc');
		}
		$query = $this->db->get();
		return $query->result();
	}
	
	public function getCount($user_id){
		$this->db->select('count(distinct id) as num');
		$this->db->from($this->table);
		$this->db->where('user_id',$user_id);
		$this->formfilter->doFilter();
		$tmp = $this->db->get()->result();
		return (int)$tmp[0]->num;
	}
	
	public function getById($id){
		$query = $this->db->where('id',$id)->get($this->table);
		return $query->row();
	}
	
}
